@x12i/reportic-render-html 0.2.2 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +66 -3
- package/dist/index.js +2535 -37
- package/dist/index.js.map +1 -1
- package/package.json +6 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,16 +1,79 @@
|
|
|
1
|
-
import { SemanticNode, PreparedReport, ReportOptions, Asset } from '@x12i/reportic-core';
|
|
1
|
+
import { SemanticNode, PreparedReport, ReportOptions, Theme, Asset } from '@x12i/reportic-core';
|
|
2
2
|
import { Page, Browser } from 'playwright-core';
|
|
3
3
|
|
|
4
4
|
declare function diagramVisuals(report: PreparedReport, options?: ReportOptions, validateOnly?: boolean): Promise<Map<string, string>>;
|
|
5
5
|
declare function chartSvg(node: SemanticNode, report: PreparedReport, options?: ReportOptions): string;
|
|
6
6
|
|
|
7
|
+
/** One figure as a standalone SVG. Colors come from the theme, never from the data. */
|
|
8
|
+
declare function figureSvg(node: SemanticNode, report: PreparedReport, options?: ReportOptions): string;
|
|
9
|
+
|
|
10
|
+
type ImportedAsset = {
|
|
11
|
+
bytes: Uint8Array;
|
|
12
|
+
mediaType: string;
|
|
13
|
+
name?: string;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
type ImportNote = {
|
|
17
|
+
code: string;
|
|
18
|
+
severity: 'info' | 'warning';
|
|
19
|
+
message: string;
|
|
20
|
+
/** The element the note is about, so an editor can jump to it. */
|
|
21
|
+
elementId?: string;
|
|
22
|
+
/** Sample fields that could explain a slot when more than one could. */
|
|
23
|
+
candidates?: string[];
|
|
24
|
+
};
|
|
25
|
+
/** A slot a sample could not settle: the text stays as written. */
|
|
26
|
+
type UnboundSlot = {
|
|
27
|
+
elementId: string;
|
|
28
|
+
slot: string;
|
|
29
|
+
text: string;
|
|
30
|
+
reason: 'no-match' | 'collision' | 'composed-ambiguous' | 'no-sample';
|
|
31
|
+
candidates?: string[];
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
type PageSetup = {
|
|
35
|
+
size?: 'A4' | 'Letter';
|
|
36
|
+
landscape?: boolean;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/** The same text is in docs/import-html.md. A test keeps the two together. */
|
|
40
|
+
declare const IMPORT_GUIDE = "Reportic reads two kinds of HTML.\n\n- Reportic HTML is a report Reportic exported: it has the generator tag \"Reportic 0.2\", a main.reportic-report element, and sections marked with data-reportic-type and data-reportic-id. It is imported exactly: every section comes back as the element that made it, with the same ids, and the colors and fonts are matched to a preset theme.\n- Any other HTML is imported best effort. A real HTML parser reads it, scripts, forms, frames and event handlers are dropped, and only structure that is clear becomes an element. Everything else stays Markdown, and what was left out is listed in the notes.\n\nWhat a best-effort import maps\n- Headings, paragraphs, lists, quotes and links stay Markdown.\n- A data table becomes a table (a grid of written-out cells). A table with three columns and a blank first header becomes a comparison.\n- A definition list becomes a two-column table with row headers.\n- A group of two or more short number-and-label blocks becomes metrics.\n- A titled aside, or a block with a callout, alert, note, or warning class, becomes a callout.\n- A progress or meter element (or role=\"progressbar\") with a value from 0 to 1 becomes a progress list.\n- A list of checkbox items becomes a checklist.\n- Three or more headings that start with a date become a timeline.\n- pre and code become a code block. A mermaid block becomes a diagram. Labeled boxes joined by arrows become a flowchart.\n- An image with a caption becomes an image. Images must be embedded (data: URIs); linked files cannot be read.\n- A trailing ordered list of links becomes sources, and earlier paragraphs with [1] style markers become narratives that cite them.\n- Colors, fonts and sizes are reduced to the nearest preset plus token overrides. A block style that differs from the document becomes a theme rule. Plain element rules are kept as report css. @page size and orientation are kept as the page setup.\n\nWhat has no element\n- Video, audio, frames, forms, scripts and canvases are dropped. A picture of a chart with no table of numbers stays an image.\n\nTo get an exact import\n- Re-export the report from Reportic as HTML and import that file, or\n- Mark each block with data-reportic-type and data-reportic-id, using the type names from the component library (metrics, table, chart, diagram, image, list, narrative, sources, group, repeat, reportic.callout.v1 as \"callout\", progress, timeline, comparison, checklist, code, masthead, footer, figure), put it in a main.reportic-report element, add <meta name=\"generator\" content=\"Reportic 0.2\">, and import again.\n\nData\n- The template written from HTML holds the text of that one report. Import with a JSON sample (one object, used as the dataset \"report\") and every slot that one field explains completely is bound to it. Slots that several fields could explain, and cells that could be split in more than one way, stay as written and are listed so you can bind them in the editor.";
|
|
41
|
+
declare const guideFor: (mode: "reportic" | "best-effort") => string;
|
|
42
|
+
|
|
43
|
+
type ImportOptions = {
|
|
44
|
+
/** One JSON object, used as the dataset named by `dataSet`. A slot is bound only when one field explains all of it. */
|
|
45
|
+
sample?: unknown;
|
|
46
|
+
/** The dataset name the bindings use. Defaults to "report". */
|
|
47
|
+
dataSet?: string;
|
|
48
|
+
};
|
|
49
|
+
type ImportResult = {
|
|
50
|
+
mode: 'reportic' | 'best-effort';
|
|
51
|
+
/** The page's own title: its first heading, or its <title>. Empty when the page has none. */
|
|
52
|
+
title: string;
|
|
53
|
+
template: string;
|
|
54
|
+
theme: Theme;
|
|
55
|
+
/** Report css that is not part of the theme: the caller's own css from a Reportic page, or plain element rules from another page. */
|
|
56
|
+
css: string;
|
|
57
|
+
page?: PageSetup;
|
|
58
|
+
assets: Record<string, ImportedAsset>;
|
|
59
|
+
notes: ImportNote[];
|
|
60
|
+
unbound: UnboundSlot[];
|
|
61
|
+
guide: string;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
/** Turns an HTML page into a Reportic template. A page Reportic exported comes back exactly; any other page is read for its clear structure. */
|
|
65
|
+
declare function importHtml(html: string, options?: ImportOptions): ImportResult;
|
|
66
|
+
|
|
7
67
|
declare function findBrowser(options?: ReportOptions): string | undefined;
|
|
8
68
|
declare function withBrowser<T>(options: ReportOptions, action: (page: Page, browser: Browser) => Promise<T>): Promise<T>;
|
|
9
69
|
|
|
10
70
|
declare function reportCss(report: PreparedReport, options?: ReportOptions): string;
|
|
11
71
|
declare function assetData(asset: Asset): string;
|
|
12
72
|
declare function cleanMarkdownHtml(markdown: string, report: PreparedReport, options?: ReportOptions): string;
|
|
13
|
-
declare const tableHtml: (columns: any[], cells: any[][], className?: string
|
|
73
|
+
declare const tableHtml: (columns: any[], cells: any[][], className?: string, options?: {
|
|
74
|
+
headers?: boolean;
|
|
75
|
+
rowHeader?: boolean;
|
|
76
|
+
}) => string;
|
|
14
77
|
declare function chartTable(node: SemanticNode, report: PreparedReport): {
|
|
15
78
|
columns: any[];
|
|
16
79
|
cells: any;
|
|
@@ -24,4 +87,4 @@ declare function renderMarkdown(report: PreparedReport, options?: ReportOptions)
|
|
|
24
87
|
assets: Asset[];
|
|
25
88
|
}>;
|
|
26
89
|
|
|
27
|
-
export { assetData, chartSvg, chartTable, cleanMarkdownHtml, diagramVisuals, findBrowser, renderHtml, renderMarkdown, reportCss, tableHtml, withBrowser };
|
|
90
|
+
export { IMPORT_GUIDE, type ImportNote, type ImportOptions, type ImportResult, type ImportedAsset, type PageSetup, type UnboundSlot, assetData, chartSvg, chartTable, cleanMarkdownHtml, diagramVisuals, figureSvg, findBrowser, guideFor, importHtml, renderHtml, renderMarkdown, reportCss, tableHtml, withBrowser };
|